﻿using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Partner.Surround.Migrations
{
    public partial class AddEntity_DataDictionary : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Core_DataDictionary",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    TypeName = table.Column<string>(maxLength: 30, nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Core_DataDictionary", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Core_DataDictionaryItem",
                columns: table => new
                {
                    Id = table.Column<long>(nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Code = table.Column<string>(maxLength: 5, nullable: true),
                    Name = table.Column<string>(maxLength: 30, nullable: true),
                    DataDictionaryId = table.Column<long>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Core_DataDictionaryItem", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Core_DataDictionaryItem_Core_DataDictionary_DataDictionaryId",
                        column: x => x.DataDictionaryId,
                        principalTable: "Core_DataDictionary",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Core_DataDictionaryItem_DataDictionaryId",
                table: "Core_DataDictionaryItem",
                column: "DataDictionaryId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Core_DataDictionaryItem");

            migrationBuilder.DropTable(
                name: "Core_DataDictionary");
        }
    }
}
